package com.tudouji.project.system.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.tudouji.framework.aspectj.lang.annotation.Log;
import com.tudouji.framework.aspectj.lang.enums.BusinessType;
import com.tudouji.project.system.domain.Fileinfo;
import com.tudouji.project.system.service.IFileinfoService;
import com.tudouji.framework.web.controller.BaseController;
import com.tudouji.framework.web.domain.AjaxResult;
import com.tudouji.common.utils.poi.ExcelUtil;
import com.tudouji.framework.web.page.TableDataInfo;

/**
 * 附件信息Controller
 * 
 * @author tudouji
 * @date 2021-05-12
 */
@RestController
@RequestMapping("/system/fileinfo")
public class FileinfoController extends BaseController
{
    @Autowired
    private IFileinfoService fileinfoService;


    /**
     * 查询附件信息列表
     */
    @GetMapping("/getFileinfo")
    public AjaxResult getFileinfo(@RequestParam("orderid") String orderid)
    {
        Fileinfo fileinfo = new Fileinfo();
        fileinfo.setLinkid(orderid);
        List<Fileinfo> list = fileinfoService.selectFileinfoList(fileinfo);
        return AjaxResult.success(list);
    }

    /**
     * 查询附件信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:fileinfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(Fileinfo fileinfo)
    {
        startPage();
        List<Fileinfo> list = fileinfoService.selectFileinfoList(fileinfo);
        return getDataTable(list);
    }

    /**
     * 导出附件信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:fileinfo:export')")
    @Log(title = "附件信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Fileinfo fileinfo)
    {
        List<Fileinfo> list = fileinfoService.selectFileinfoList(fileinfo);
        ExcelUtil<Fileinfo> util = new ExcelUtil<Fileinfo>(Fileinfo.class);
        return util.exportExcel(list, "fileinfo");
    }

    /**
     * 获取附件信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:fileinfo:query')")
    @GetMapping(value = "/{guid}")
    public AjaxResult getInfo(@PathVariable("guid") String guid)
    {
        return AjaxResult.success(fileinfoService.selectFileinfoById(guid));
    }

    /**
     * 新增附件信息
     */
    @PreAuthorize("@ss.hasPermi('system:fileinfo:add')")
    @Log(title = "附件信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Fileinfo fileinfo)
    {
        return toAjax(fileinfoService.insertFileinfo(fileinfo));
    }

    /**
     * 修改附件信息
     */
    @PreAuthorize("@ss.hasPermi('system:fileinfo:edit')")
    @Log(title = "附件信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Fileinfo fileinfo)
    {
        return toAjax(fileinfoService.updateFileinfo(fileinfo));
    }

    /**
     * 删除附件信息
     */
    @PreAuthorize("@ss.hasPermi('system:fileinfo:remove')")
    @Log(title = "附件信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{guids}")
    public AjaxResult remove(@PathVariable String[] guids)
    {
        return toAjax(fileinfoService.deleteFileinfoByIds(guids));
    }
}
